package com.itheima.health.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.health.common.R;
import com.itheima.health.entity.CheckItem;
import com.itheima.health.service.CheckuItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/checkItem")

public class CheckItemController {
    @Autowired
    private CheckuItemService checkItemService;

    /*
     * 新增
     * */
    @PostMapping
    public R<String> save(@RequestBody CheckItem checkItem) {
        System.out.println(checkItem);
        checkItemService.save(checkItem);
        return R.success("添加成功");
    }

    /**
     * 分页
     */
    @GetMapping("/page")
    public R<Page<CheckItem>> page(int page, int pageSize , String name) {

        Page<CheckItem> pageInfo = new Page<>(page, pageSize);
        LambdaQueryWrapper<CheckItem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(name != null, CheckItem::getName,name);
        queryWrapper.orderByAsc(CheckItem::getCode);

        checkItemService.page(pageInfo, queryWrapper);
        return R.success(pageInfo);


    }

}
